# Imports
import math as m
import numpy as np
import matplotlib.pyplot as plt
import holoviews as hv
import pylab as pl
from pylab import exp,cos,sin,pi,tan, pi
import pandas as pd
import seaborn as sb
import holoviews as hv
from IPython.display import SVG
import io
from PIL import Image
from random import random
import elastica as el
import elastica_neurons as en
from dynamics import *
%matplotlib inline
hv.notebook_extension()
m = 11
n = 11
np.random.seed(42)
ac_orient1 = np.pi*np.random.rand(m,n)
ac_orient1[2:8,5] = 0
visualField(ac_orient1)
ac_orient2 = np.pi/2*np.ones((m,n))
ac_orient2[5,5] = 0
visualField(ac_orient2)
ac_orient3 = np.pi/2*np.ones((m,n))
for i in range(m):
ac_orient3[i,i] = 3*np.pi/4
visualField(ac_orient3)
np.random.seed(67)
ac_orient4 = np.pi*np.random.rand(m,n)
ac_orient4[2:8,6] = np.random.rand(6)/5
visualField(ac_orient4)
m = 5
n = 2
dimensions = ['X', 'Y']
ac_orient = np.reshape(np.pi*np.arange(m*n)/(m*n), (m,n))
keys = [(i,j) for i in range(m) for j in range(n)]
vf_holomap = hv.HoloMap([(k, visualField(ac_orient[k])) for k in keys], kdims=dimensions)
vf_holomap
a = np.ones(3)
b = np.arange(0,1.5,0.5)
curve1 = hv.Curve(zip(a,b))
curve2 = hv.Curve(zip(b,a))
curve1*curve2(style={'visible':False})
a = np.ones(5)
b = np.arange(0,0.5,0.1)
curve2 = hv.Curve(zip(b,a))
#b*curve2
a = np.ones(3)
b = np.arange(0,1.5,0.5)
curve1 = hv.Curve(zip(np.tile(1, 3),b))
curve2 = hv.Curve(zip(b,np.tile(1, 3)))
a = np.ones(5)/2
b = np.arange(0.3,0.8,0.1)
curve1*curve2(style={'visible':False})*hv.Curve(zip(b,a))
%output size=100
plotbar(1,1,1,width=4)
x = -np.matrix(np.arange(12).reshape((3,4))); x
type(x)
%output size=400
#ac_orient = np.array([[0],[np.pi/4],[np.pi/2],[3*np.pi/4]])
ac_orient = np.array([[-0.1],[0.2]])
mag = np.array([[1],[1]])
a = visualField(ac_orient, aspect=2, fix_scale=True)
a
Generate weight matrices
We define full connectivity matrices. Every orientation selective neuron from part of the visual field is connected to all other orientation selective neurons from other parts of the visual field. Let's say we have a visual field with size 10x10, with 9 orientation selective neurons for each field. In order to have a full connectivity matrix, we define an mxm matrix, where m=10109. In this way we define the stregth of every neuron to every other neuron. We don't have any connections between neurons in the same part of the visual field. Try to do checks either by visualizing or simple sanity checks. For example we can check if we have setup the correct connection to zero. Number of all connection - 810000, from which 10109*9=8100 should not be connect to each other. When we check that's indeed the case.
%%output size=150
m = 1
n = 2
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.1
orientation_scaling = 0.1
results, rs, direction, magnitude = runExperiment('my',m,n,nosn,ac_orient,timesteps,tau,k=0.25,A=3)
results
magnitude[0,0,:]
%%output size=150
t = np.arange(0,timesteps,1)
setNumberOfColors(nosn)
plotOneField((0,0),t,nosn,rs)
plt.plot(direction[0,0,:])
sum(sum(matrix2))
%%output size=300
matrix2 = np.load('weight_matrices/10x10x9my.npy')
plt.figure(figsize=[20, 20])
plt.imshow(matrix2)
plt.colorbar()
a.shape[0]
%%output size=300
a = generateWeightMatrix(type='my', m=1,n=2, nosn=9, distance_factor=0.003, orientation_factor=0.001)
showWeights(a,fig_size=20)
%%output size=300
a = generateWeightMatrix(type='el', m=8,n=8,nosn=9)
showWeights(a,fig_size=30)
%%output size=150
m = 10
n = 10
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.00005
orientation_scaling = 0.00005
# Set the number of colors for plotting, based on the number of orientation selective neurons
setNumberOfColors(nosn)
orientations = np.arange(0, np.pi, np.pi/nosn)
#ac_orient = np.random.rand(m,n)
responses = np.zeros((nosn, timesteps))
t = np.arange(0,timesteps,1)
spikes_ = vonMises(A,k,ac_orient,orientations)
spikes = spikes_.ravel()
r = np.zeros(len(spikes))
drdt = spikes/tau
rs = np.zeros(spikes.shape + (len(t),))
for s in range(len(t)):
r = r + drdt
drdt = (-r + spikes)/tau + np.dot(matrix,r)
rs[:,s] = r
#r_first_neuron = rs[:,1,1,:]
rs = np.reshape(rs, spikes_.shape + (len(t),))
#(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
#dimensions = ['T']
#keys = [i for i in range(timesteps)]
#oneColor()
#r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
#sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
#sections
rs.shape
plotOneField((1,0),t,nosn,rs)
#r_first_neuron = rs[:,1,1,:]
m = 10
n = 10
tau = 6
timesteps = 100
# Number of orientation selective neurons
nosn = 9
orientations = np.arange(0, np.pi, np.pi/nosn)
rs = np.load('weight_matrices/10x10x9my_rs.npy')
(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
dimensions = ['T']
keys = [i for i in range(timesteps)]
oneColor()
r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
sections
t = np.arange(0,timesteps,1)
plotOneField((1,0),t,nosn,rs)
%%output size=300
m = 10
n = 10
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.00005
orientation_scaling = 0.00005
# Set the number of colors for plotting, based on the number of orientation selective neurons
setNumberOfColors(nosn)
orientations = np.arange(0, np.pi, np.pi/nosn)
#ac_orient = np.random.rand(m,n)
responses = np.zeros((nosn, timesteps))
t = np.arange(0,timesteps,1)
spikes_ = vonMises(A,k,ac_orient,orientations)
spikes = spikes_.ravel()
r = np.zeros(len(spikes))
drdt = spikes/tau
rs = np.zeros(spikes.shape + (len(t),))
for s in range(len(t)):
r = r + drdt
drdt = (-r + spikes)/tau + np.dot(matrix2,r)
rs[:,s] = r
#r_first_neuron = rs[:,1,1,:]
rs = np.reshape(rs, spikes_.shape + (len(t),))
(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
dimensions = ['T']
keys = [i for i in range(timesteps)]
oneColor()
r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
sections